package com.software.levelupserver.utils;

import com.software.levelupserver.entity.Task;

public class ExperienceUtil {

    /**
     * <h2>根据公式计算每个任务的经验值</h2>
     * <table border="1">
     *   <thead>
     *     <tr>
     *       <th>任务元素</th>
     *       <th>经验值</th>
     *       <th>条件</th>
     *     </tr>
     *   </thead>
     *   <tbody>
     *     <tr>
     *       <td>优先级（不重要不紧急）</td>
     *       <td>+1</td>
     *       <td></td>
     *     </tr>
     *     <tr>
     *       <td>优先级（不重要紧急）</td>
     *       <td>+2</td>
     *       <td></td>
     *     </tr>
     *     <tr>
     *       <td>优先级（重要不紧急）</td>
     *       <td>+3</td>
     *       <td></td>
     *     </tr>
     *     <tr>
     *       <td>优先级（重要且紧急）</td>
     *       <td>+4</td>
     *       <td></td>
     *     </tr>
     *     <tr>
     *       <td>待办</td>
     *       <td>+1</td>
     *       <td></td>
     *     </tr>
     *     <tr>
     *       <td>通知型任务</td>
     *       <td>+2</td>
     *       <td></td>
     *     </tr>
     *     <tr>
     *       <td>计时型任务</td>
     *       <td>+5</td>
     *       <td></td>
     *     </tr>
     *     <tr>
     *       <td>1分钟</td>
     *       <td>+0.2</td>
     *       <td></td>
     *     </tr>
     *     <tr>
     *       <td>10分钟</td>
     *       <td>+2</td>
     *       <td></td>
     *     </tr>
     *     <tr>
     *       <td>第二天的任务设置（晚上签到）</td>
     *       <td>+10</td>
     *       <td></td>
     *     </tr>
     *   </tbody>
     * </table>
     * @param task
     * @return
     */
    public static double getExperience(Task task){

        double experience = 0;

        Integer priority = task.getPriority();
        experience += (priority + 1);

        Integer taskType = task.getTaskType();
        switch (taskType){
            case 0:
                experience += 1;
                break;
            case 1:
                experience += 2;
                break;
            case 2:
                experience += 5;
                String startTime = task.getStartTime();
                String endTime = task.getEndTime();
                if (startTime != null && endTime != null){
                    long minutesDuration = DateUtil.getMinutesDuration(startTime, endTime);
                    experience += (minutesDuration*0.2);
                }
                break;
            default:
                break;
        }

        return experience;
    }
}
